package org.bw.bookstore.book.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.bw.bookstore.book.service.BookService;
import org.bw.bookstore.common.entity.TbBookDetailed;
import org.bw.bookstore.common.entity.TbBookSingle;
import org.bw.bookstore.common.entity.TbBookType;
import org.bw.bookstore.common.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;

/**
*@program: wisdom_bookstore
*@description: 书籍控制层
*@author: 孙冬雪
*@create: 2020-10-25 11:08
*/
@RestController
@CrossOrigin
@Slf4j
@RequestMapping("/book")
@Api(tags = "接口-书籍管理")
public class BookController {

    @Autowired
    private BookService bookService;

    /**
     * @Description
     * TODO 孙冬雪--> addBookDetailed 添加书籍详情
     * @Param [bookDetailed]
     * @Return com.bw.servercommon.utils.ResponseResult
     * @Author 孙冬雪
     * @Date 2020/10/22 19:33
     **/
    @PostMapping("/addBookDetailed")
    @ApiOperation(value="添加书籍详情", notes="添加书籍详情")
/*    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "bookName", value = "书籍名称",dataType = "String",required = true),
            @ApiImplicitParam(name = "bookPrice", value = "书籍价格",dataType = "Double",required = true),
            @ApiImplicitParam(name = "author", value = "书籍作者",dataType = "String",required = true),
            @ApiImplicitParam(name = "publishingHouse", value = "书籍出版社",dataType = "String",required = true),
            @ApiImplicitParam(name = "bookDesc", value = "书籍描述",dataType = "String",required = true),
            @ApiImplicitParam(name = "briefIntroduction", value = "书籍简介",dataType = "String",required = true),
            @ApiImplicitParam(name = "supplyingParty", value = "书籍供货方",dataType = "String",required = true),
            @ApiImplicitParam(name = "bookTypeCodes", value = "图书类型code集",dataType = "String"),
            @ApiImplicitParam(name = "bookImgCodes", value = "图书插图code集",dataType = "String"),
            @ApiImplicitParam(name = "tbBookSingleList", value = "图书单品集合",dataType = "List"),
    })*/
    public ResponseResult addBookDetailed(@RequestBody TbBookDetailed bookDetailed){
        return  bookService.addBookDetailed(bookDetailed);
    }

    /**
     * @Description
     * TODO 孙冬雪--> updateBookDetailed 修改书籍详细信息
     * @Param [bookDetailed]
     * @Return com.bw.servercommon.utils.ResponseResult
     * @Author 孙冬雪
     * @Date 2020/10/22 19:32
     **/
    @PostMapping("/updateBookDetailed")
    @ApiOperation(value="修改书籍详细信息", notes="修改书籍详细信息")
    /*@ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "书籍ID",dataType = "Integer",required = true),
            @ApiImplicitParam(name = "bookName", value = "书籍名称",dataType = "String",required = true),
            @ApiImplicitParam(name = "bookPrice", value = "书籍价格",dataType = "Double",required = true),
            @ApiImplicitParam(name = "author", value = "书籍作者",dataType = "String",required = true),
            @ApiImplicitParam(name = "publishingHouse", value = "书籍出版社",dataType = "String",required = true),
            @ApiImplicitParam(name = "bookDesc", value = "书籍描述",dataType = "String",required = true),
            @ApiImplicitParam(name = "briefIntroduction", value = "书籍简介",dataType = "String",required = true),
            @ApiImplicitParam(name = "supplyingParty", value = "书籍供货方",dataType = "String",required = true),
            @ApiImplicitParam(name = "bookTypeCodes", value = "图书类型code集",dataType = "String"),
            @ApiImplicitParam(name = "bookImgCodes", value = "图书插图code集",dataType = "String"),
    })*/
    public ResponseResult updateBookDetailed(@RequestBody TbBookDetailed bookDetailed){
        return bookService.updateBookDetailed(bookDetailed);
    }

    /**
     * @Description
     * TODO 孙冬雪--> delBookDetailed 书籍下架
     * @Param [bookDetailedId]
     * @Return com.bw.servercommon.utils.ResponseResult
     * @Author 孙冬雪
     * @Date 2020/10/22 19:32
     **/
    @PostMapping("/delBookDetailed")
    @ApiOperation(value="书籍下架", notes="书籍下架")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "bookDetailedId", value = "书籍详情id",dataType = "Integer",required = true),
            @ApiImplicitParam(name = "deletedStatus", value = "上架状态",dataType = "Integer",required = true)
    })
    public ResponseResult delBookDetailed(Integer bookDetailedId, Integer deletedStatus){
        return bookService.delBookDetailed(bookDetailedId, deletedStatus);
    }

    /**
     * @Description
     * TODO 孙冬雪--> findAllBookDetailed 查看所有书籍
     * @Param []
     * @Return com.bw.servercommon.utils.ResponseResult
     * @Author 孙冬雪
     * @Date 2020/10/22 19:34
     **/
    @PostMapping("/findAllBookDetailed")
    @ApiOperation(value="查看所有书籍", notes="查看所有书籍")
    public ResponseResult findAllBookDetailed(){
        return bookService.findAllBookDetailed();
    }

    /**
     * @Description 通过RFID判断是否未付款，最后返回未付款书籍详情
     * TODO 孙冬雪--> findDetailedByRFID 返回未付款书籍详情
     * @Param [rfids]
     * @Return com.bw.servercommon.utils.ResponseResult
     * @Author 孙冬雪
     * @Date 2020/10/22 19:38
     **/
    @PostMapping("/findDetailedByRFID")
    @ApiOperation(value="检测是否有未付款书籍", notes="检测是否有未付款书籍")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "rfids", value = "RFID集合",dataType = "String")
    })
    public ResponseResult findDetailedByRFID(String rfids){
        return bookService.findDetailedByRFID(rfids);
    }

    /**
     * @Description
     * TODO 孙冬雪--> findDetailedById 根据ID查找对应书籍详情
     * @Param [bookDetailedId]
     * @Return com.bw.servercommon.utils.ResponseResult
     * @Author 孙冬雪
     * @Date 2020/10/25 11:06
     **/
    @PostMapping("/findDetailedById")
    @ApiOperation(value="根据ID查找对应书籍详情", notes="根据ID查找对应书籍详情")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "bookDetailedId", value = "书籍详情ID",dataType = "Integer")
    })
    public ResponseResult findDetailedById(Integer bookDetailedId){
        return bookService.findDetailedById(bookDetailedId);
    }

    /**
     * @Description 
     * TODO 孙冬雪--> addBookSingle 添加书籍单品
     * @Param [bookSingle] 
     * @Return com.bw.servercommon.utils.ResponseResult
     * @Author 孙冬雪
     * @Date 2020/10/26 11:57
     **/
    @PostMapping("/addBookSingle")
    @ApiOperation(value="添加书籍单品", notes="添加书籍单品")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "rfid", value = "单品唯一RFID",dataType = "Integer",required = true),
            @ApiImplicitParam(name = "qrCode", value = "单品唯一二维码",dataType = "Integer",required = true),
            @ApiImplicitParam(name = "bookDetailedCode", value = "书籍详情code标识",dataType = "String",required = true),
            @ApiImplicitParam(name = "shopCode", value = "书店唯一标识",dataType = "String",required = true)
    })
    public ResponseResult addBookSingle(@ApiIgnore @RequestBody TbBookSingle bookSingle){
        return bookService.addBookSingle(bookSingle);
    }

    /**
     * @Description
     * TODO 孙冬雪--> sellBookSingle 售卖书籍单品
     * @Param [bookSingleId]
     * @Return com.bw.servercommon.utils.ResponseResult
     * @Author 孙冬雪
     * @Date 2020/10/22 19:38
     **/
    @PostMapping("/sellBookSingle")
    @ApiOperation(value="售卖书籍单品", notes="售卖书籍单品")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "bookSingleId", value = "书籍单品主键id",dataType = "int",required = true)
    })
    public ResponseResult sellBookSingle(@RequestParam("bookSingleId") Integer bookSingleId){
        return bookService.sellBookSingle(bookSingleId);
    }

    /**
     * @Description 
     * TODO 孙冬雪--> delBookSingle 删除书籍单品
     * @Param [bookSingleId] 
     * @Return com.bw.servercommon.utils.ResponseResult
     * @Author 孙冬雪
     * @Date 2020/10/27 9:08
     **/
    @PostMapping("/delBookSingle")
    @ApiOperation(value="删除书籍单品", notes="删除书籍单品删除书籍单品")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "bookSingleId", value = "书籍单品主键id",dataType = "int",required = true)
    })
    public ResponseResult delBookSingle(@RequestParam("bookSingleId") Integer bookSingleId){
        return bookService.delBookSingle(bookSingleId);
    }

    /**
     * @Description
     * TODO 孙冬雪--> findSingleListByDetailed 根据书籍详情删除单品书籍
     * @Param [bookDetailedCode]
     * @Return com.bw.servercommon.utils.ResponseResult
     * @Author 孙冬雪
     * @Date 2020/10/27 9:18
     **/
    @PostMapping("/findSingleListByDetailed")
    @ApiOperation(value="根据书籍详情删除单品书籍", notes="根据书籍详情删除单品书籍")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "bookDetailedCode", value = "书籍详情code",dataType = "String",required = true)
    })
    public ResponseResult findSingleListByDetailed(String bookDetailedCode){
        return bookService.findSingleListByDetailed(bookDetailedCode);
    }

    /**
     * @Description
     * TODO 孙冬雪--> addBookType 添加图书类型
     * @Param [bookType]
     * @Return com.bw.servercommon.utils.ResponseResult
     * @Author 孙冬雪
     * @Date 2020/10/22 20:07
     **/
    @PostMapping("/addBookType")
    @ApiOperation(value="添加图书类型", notes="添加图书类型")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "bookTypeName", value = "图书类型名称",dataType = "String",required = true)
    })
    public ResponseResult addBookType(@ApiIgnore @RequestBody TbBookType bookType){
        return bookService.addBookType(bookType);
    }

    /**
     * @Description
     * TODO 孙冬雪--> updateBookType 修改图书类型
     * @Param [bookType]
     * @Return com.bw.servercommon.utils.ResponseResult
     * @Author 孙冬雪
     * @Date 2020/10/22 20:06
     **/
    @PostMapping("/updateBookType")
    @ApiOperation(value="修改图书类型", notes="修改图书类型")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "图书类型ID",dataType = "Integer",required = true),
            @ApiImplicitParam(name = "bookTypeName", value = "图书类型名称",dataType = "String",required = true)
    })
    public ResponseResult updateBookType(@ApiIgnore @RequestBody TbBookType bookType){
        return bookService.updateBookType(bookType);
    }

    /**
     * @Description
     * TODO 孙冬雪--> delBookType 逻辑删除图书类型
     * @Param [bookTypeId]
     * @Return com.bw.servercommon.utils.ResponseResult
     * @Author 孙冬雪
     * @Date 2020/10/22 20:06
     **/
    @PostMapping("/delBookType")
    @ApiOperation(value="删除图书类型", notes="删除图书类型")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "bookTypeId", value = "图书类型ID",dataType = "Integer",required = true)
    })
    public ResponseResult delBookType(@RequestParam("bookTypeId") Integer bookTypeId){
        return bookService.delBookType(bookTypeId);
    }

    /**
     * @Description
     * TODO 孙冬雪--> findAllBookType 查找所有图书类型
     * @Param []
     * @Return com.bw.servercommon.utils.ResponseResult
     * @Author 孙冬雪
     * @Date 2020/10/23 10:18
     **/
    @PostMapping("/findAllBookType")
    @ApiOperation(value="查找所有图书类型", notes="查找所有图书类型")
    public ResponseResult findAllBookType() {
        return bookService.findAllBookType();
    }

    /**
     * @Description
     * TODO 孙冬雪--> findBookTypeById 根据图书类型ID查找图书类型
     * @Param [bookTypeId]
     * @Return com.bw.servercommon.utils.ResponseResult
     * @Author 孙冬雪
     * @Date 2020/10/25 11:48
     **/
    @PostMapping("/findBookTypeById")
    @ApiOperation(value="根据图书类型ID查找图书类型", notes="根据图书类型ID查找图书类型")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "bookTypeId", value = "图书类型ID",dataType = "Integer",required = true)
    })
    public ResponseResult findBookTypeById(Integer bookTypeId){
        return bookService.findBookTypeById(bookTypeId);
    }

    /**
     * @Description
     * TODO 孙冬雪--> addBookImg 添加图书插图
     * @Param [files, bookDetailedCode]
     * @Return com.bw.servercommon.utils.ResponseResult
     * @Author 孙冬雪
     * @Date 2020/10/24 16:51
     **/
    @PostMapping("/addBookImg")
    @ApiOperation(value="添加图书插图", notes="添加图书插图")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "bookImgUrls", value = "插图URL路径",dataType = "String",required = true),
            @ApiImplicitParam(name = "bookDetailedCode", value = "图书详情标识",dataType = "String",required = true)
    })
    public ResponseResult addBookImg(@RequestParam("bookImgUrls") String bookImgUrls,
                                     @RequestParam("bookDetailedCode")String bookDetailedCode){
        return bookService.addBookImgBash(bookImgUrls, bookDetailedCode);
    }

    /**
     * @Description
     * TODO 孙冬雪--> findBookImgByBook 根据图书查找对应插图
     * @Param [bookDetailedCode]
     * @Return com.bw.servercommon.utils.ResponseResult
     * @Author 孙冬雪
     * @Date 2020/10/24 16:51
     **/
    @PostMapping("/findBookImgByBook")
    @ApiOperation(value="根据图书查找对应插图", notes="根据图书查找对应插图")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "bookDetailedCode", value = "图书详情标识",dataType = "String",required = true)
    })
    public ResponseResult findBookImgByBook(@RequestParam("bookDetailedCode")String bookDetailedCode) {
        return bookService.findBookImgByBook(bookDetailedCode);
    }

    /**
     * @Description 
     * TODO 孙冬雪--> uploadImg 上传图片
     * @Param [file] 
     * @Return com.bw.servercommon.utils.ResponseResult
     * @Author 孙冬雪
     * @Date 2020/10/25 14:40
     **/
    @PostMapping("/uploadImg")
    @ApiOperation(value="上传图片", notes="上传图片")
    /*@ApiImplicitParams(value = {
            @ApiImplicitParam(name = "file", value = "文件",dataType = "File",required = true)
    })*/
    public ResponseResult uploadImg(MultipartFile file){
        return this.bookService.uploadImg(file);
    }

}
